﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Text;
using System.Windows.Forms;

namespace 学生成绩管理系统
{
    
    public partial class Frmaddzyxx : Form
    {
        private string o_id=null;
        public Frmaddzyxx()
        {
            InitializeComponent();

        }   
        public Frmaddzyxx(string id)
        {
            InitializeComponent();
            this.o_id = id;
            if (o_id != "")
            {
                SpecialtyInfoData info = new SpecialtyInfoData();
                info.Specialtyid = id;
                DataSet ds = SpecialtyOperation.getSpecialty(info);
                this.TxtId.Text = ds.Tables[0].Rows[0]["专业id"].ToString();
                this.TxtName.Text = ds.Tables[0].Rows[0]["专业名称"].ToString();
                this.TxtId.Enabled = false;
                this.Text = "专业信息修改";
            }
        }
        private void btnSearch_Click(object sender, EventArgs e)
        {
            string id = this.TxtId.Text;
            string name = this.TxtName.Text;
            if(id==null||id.Trim().Equals(""))
            {//专业代号不允许为空
                MessageBox.Show("请输入专业id!","提示");
                this.TxtId.Focus();
                return;
            }
            if(name==null||name.Trim().Equals(""))
            {//专业名称不允许为空
                MessageBox.Show("请输入专业名称","提示");
                this.TxtName.Focus();
                return;
            }
            SpecialtyInfoData data = new SpecialtyInfoData();
            data.Specialtyid = id;
            data.Specialtymc = name;
            try
            {
                if (o_id == "")
                {
                    if (SpecialtyOperation.insertSpecialty(data))
                    {
                        MessageBox.Show("添加成功！", "提示");
                        this.TxtId.Text = "";
                        this.TxtName.Text = "";
                    }
                    else
                    {
                        MessageBox.Show("添加失败!", "错误");
                    }
                }
                else
                {
                    if (SpecialtyOperation.updateSpecialty(data))
                    {
                        MessageBox.Show("修改成功！", "提示");
                        //((Frmzyxxcx)this.Parent).bindDataGrid();
                        //this.Dispose();
                    }
                    else
                    {
                        MessageBox.Show("修改失败！","错误");
                    }
                }
            }
            catch(Exception ex)
            {
                ex.ToString();
                MessageBox.Show("保存失败！","错误");
            }
           
        }

        private void BtnCannel_Click(object sender, EventArgs e)
        {
            this.Dispose();
        }
    }
}